package com.hitqz.robot.biz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {

    @Bean("customThreadPool")
    public ExecutorService customThreadPool() {
        return new ThreadPoolExecutor(
                5,
                50,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean("videoPushThreadPool")
    public ExecutorService videoPushThreadPool() {
        return new ThreadPoolExecutor(
                4*4,
                4*12,
                1L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean("websocketSendThreadPool")
    public ExecutorService websocketSendThreadPool() {
        return new ThreadPoolExecutor(
                20,
                100,
                200L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy()
        );
    }

    @Bean("ticketsThreadPool")
    public ExecutorService ticketsThreadPool() {
        return new ThreadPoolExecutor(
                10,
                50,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }


}
